/*
Copyright (c) 2010 Peter "Corsix" Cawley

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "lua.hpp"
#include <string.h>

/* Often, an error occurs during the CorsixTH startup process. Examples of
such errors include:
  1) Unable to find CorsixTH.lua
  2) Incorrect theme_hospital_install setting
  3) Lua syntax error in modified file
When such errors occur, we want to report them to the user. The simple way of
doing this is printing the error details to stdout. Unfortunately, Windows
users tend to disregard stdout, and OS X users never see it unless launching
CorsixTH from a terminal. Hence the approach taken is to print the error
details to our game window. Doing so is not trivial though, as we cannot rely
on having any external Lua scripts or external graphical resources. Thus the
font data and Lua script are hardcoded into this file (the font itself is a
homemade bitmap font, as we cannot rely on TH fonts being present).
*/

int g_iBootstrapCodeLineNumStart = __LINE__ + 2;
const char* g_sBootstrapCode[] = {
    "local lines, dat, tab, pal, err = {}, ...",
    "local function t(s) return s:gsub('\\t', '  ') end",
    "for s in tostring(err):gmatch'[^\\r\\n]+' do lines[#lines+1] = t(s) end",
    "local TH, SDL, rnc = require'TH', require'sdl', require'rnc'.decompress",
    "if not SDL.init('video') then error'Unable to initialise video' end",
    "SDL.wm.setCaption('CorsixTH - Error during startup')",
    "local w, h = 640, 480",
    "local modes = {'hardware', 'doublebuf'}",
    "local function dernc(x) return x:match'^RNC' and assert(rnc(x)) or x end",
    "local video = TheApp and TheApp.video or TH.surface(w, h, unpack(modes))",
    "local palette, sheet, font = TH.palette(), TH.sheet(), TH.bitmap_font()",
    "if not palette:load(dernc(pal)) then error'Unable to load palette' end",
    "sheet:setPalette(palette)",
    "if not sheet:load(dernc(tab), dernc(dat), true, video) then error'Unable to load sheet' end",
    "font:setSheet(sheet):setSeparation(1, 0)",
    "local bx, by, bw, bh = 20, 0, 100, 16", // Print message and draw button:
    "local function draw()",
    " video:startFrame()",
    " video:fillBlack()",
    " local y = 20",
    " for _, s in ipairs(lines) do",
    "  y = font:drawWrapped(video, s, 20, y, w - 40)",
    " end",
    " by = y + 20",
    " video:drawRect(video:mapRGB(151, 23, 23), bx, by, bw, bh)",
    " video:drawRect(video:mapRGB(171, 53, 53), bx + 1, by + 1, bw - 2, bh - 2)",
    " font:draw(video, 'Exit', bx, by + 1, bw, bh)",
    " video:endFrame()",
    "end",
    "SDL.wm.showCursor(true)",
    "draw()",
    "local running = true", // Minimal event handler:
    "repeat",
    " local e, where = SDL.mainloop(coroutine.create(function()",
    "  while running do",
    "   local e, _, x, y = coroutine.yield(true)",
    "   if e == 'frame' then draw()",
    "   elseif e == 'buttonup' then",
    "    x, y = x - bx, y - by",
    "    running = x < 0 or bw <= x or y < 0 or bh <= y",
    "   end",
    "  end",
    " end))",
    " if running then print(e) end",
    "until where ~= 'callback'",
    NULL
};

/* Start autogenerated content */
/* Data from bootstrap_font.tab inserted by mkbootstrap.lua: */
const unsigned char g_aBootstrapFontTab[] = {
0x52, 0x4E, 0x43, 0x01, 0x00, 0x00, 0x05, 0x46, 0x00, 0x00, 0x01, 0xE1, 0xFB, 
0xF2, 0x66, 0x51, 0xBE, 0xEF, 0x0C, 0x09, 0x59, 0x60, 0x10, 0x34, 0x43, 0x54, 
0xA6, 0x46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, 0xA4, 0xCA, 0x6C, 0xCD, 0x4C, 0x86, 0x94, 0x92, 0xEA, 0xA5, 
0x7F, 0x39, 0xD9, 0x72, 0xAF, 0x11, 0x10, 0x04, 0xAA, 0x1C, 0xED, 0x47, 0x3D, 
0xF6, 0x97, 0x3D, 0xF4, 0x7D, 0x0A, 0x5E, 0xAF, 0x44, 0x80, 0xAA, 0x57, 0x35, 
0xAA, 0xA1, 0xF7, 0x34, 0xBA, 0x92, 0xA4, 0xD6, 0xF7, 0x7A, 0xF7, 0x5B, 0x1A, 
0x18, 0x11, 0x35, 0xAA, 0xC4, 0x48, 0xAA, 0x4C, 0x6E, 0xD6, 0x91, 0x93, 0x12, 
0x52, 0xBA, 0xE0, 0x35, 0x8D, 0xFF, 0x5C, 0x1F, 0x27, 0x12, 0x54, 0xE9, 0x44, 
0x51, 0xA5, 0x67, 0x47, 0x92, 0x7F, 0x99, 0x64, 0x37, 0xBA, 0x38, 0x49, 0xE2, 
0xA8, 0xCF, 0xF2, 0x75, 0x53, 0x0D, 0x13, 0xFA, 0x24, 0x1E, 0x51, 0xB9, 0xC9, 
0x29, 0x40, 0x52, 0x7D, 0x0F
};
/* Data from bootstrap_font.dat inserted by mkbootstrap.lua: */
const unsigned char g_aBootstrapFontDat[] = {
0x52, 0x4E, 0x43, 0x01, 0x00, 0x00, 0x13, 0x68, 0x00, 0x00, 0x05, 0xEC, 0xD3, 
0x6C, 0x7E, 0xAB, 0xBE, 0xEF, 0x94, 0x90, 0x81, 0x61, 0x50, 0x34, 0x44, 0x33, 
0x33, 0x53, 0x66, 0x64, 0x64, 0x26, 0x20, 0x60, 0x47, 0x1E, 0x01, 0xFF, 0x84, 
0x41, 0x01, 0x02, 0xFF, 0x01, 0x84, 0x09, 0xFF, 0xFF, 0x14, 0x2F, 0x06, 0xCD, 
0x9B, 0xCC, 0x8C, 0x89, 0x04, 0x1B, 0x42, 0x06, 0x65, 0x64, 0x71, 0x3B, 0x44, 
0x01, 0x06, 0x78, 0xE0, 0xE9, 0xD9, 0x9A, 0x2B, 0x36, 0x72, 0xB0, 0x43, 0x84, 
0x59, 0x1B, 0x4D, 0x0A, 0xB6, 0x75, 0x87, 0x91, 0x32, 0xAB, 0x86, 0x02, 0xCC, 
0xDE, 0x84, 0x07, 0x82, 0x31, 0x85, 0xCC, 0x45, 0x90, 0x4A, 0x84, 0xE7, 0xC4, 
0x9C, 0x42, 0xFC, 0x29, 0x66, 0x0C, 0xA4, 0x94, 0x9D, 0xD9, 0x38, 0x75, 0x35, 
0x42, 0x98, 0x07, 0x6D, 0x70, 0x91, 0x1B, 0x03, 0x8E, 0x54, 0x40, 0x9B, 0xED, 
0x89, 0x19, 0x44, 0x87, 0x02, 0x9D, 0x8B, 0x5C, 0x3A, 0x15, 0x19, 0xF8, 0xB7, 
0xAC, 0x43, 0x01, 0x15, 0x93, 0x0B, 0x5D, 0x03, 0x83, 0x40, 0x1A, 0x56, 0xA5, 
0x1D, 0x03, 0xF2, 0x93, 0xA2, 0x50, 0x03, 0xB6, 0x11, 0x1C, 0xF2, 0x8E, 0x8E, 
0x60, 0x87, 0x42, 0x89, 0x93, 0x40, 0x93, 0x64, 0xA2, 0x81, 0x04, 0x29, 0x23, 
0x11, 0x4F, 0x36, 0xA0, 0xBA, 0x8E, 0xA2, 0xA4, 0x1A, 0x08, 0x75, 0x65, 0x6E, 
0x9C, 0xAC, 0x14, 0xC3, 0x18, 0x67, 0x33, 0x16, 0x4E, 0x10, 0x31, 0x8C, 0x11, 
0x9B, 0x17, 0x7C, 0xCC, 0x44, 0x57, 0x8F, 0xF7, 0x74, 0x0E, 0x3F, 0x71, 0x80, 
0x64, 0x08, 0x39, 0x90, 0xBC, 0x28, 0x87, 0x3A, 0x15, 0x8B, 0x70, 0x30, 0x9D, 
0x04, 0x14, 0x0B, 0x89, 0x1C, 0x95, 0x21, 0x8F, 0x50, 0xB5, 0x2D, 0xD9, 0x85, 
0x1B, 0x80, 0x72, 0xEC, 0x0A, 0xCE, 0x6B, 0x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font.pal inserted by mkbootstrap.lua: */
const unsigned char g_aBootstrapFontPal[] = {
0x52, 0x4E, 0x43, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x1D, 0xB7, 
0xFF, 0x76, 0x79, 0xBE, 0xEF, 0x90, 0x10, 0x90, 0x05, 0x01, 0x02, 0x00, 0x00, 
0x20, 0x2B, 0x04, 0x00, 0x00, 0x00, 0x40, 0x08, 0x00, 0xB6, 0x00, 0x00, 0x00, 
0x3F, 0x3F, 0x3F, 0x62, 0x79, 0xBE, 0x27, 0x3F
};
/* End autogenerated content */

// Lua reader function for loading g_sBootstrapCode
static const char* read_bootstrap_line(lua_State *L, void *data, size_t *size)
{
    int& iLine = *reinterpret_cast<int*>(data);
    ++iLine;
    if(iLine < 0 || (iLine & 1))
    {
        *size = 1;
        return "\n";
    }
    else
    {
        const char *s = g_sBootstrapCode[iLine / 2];
        if(s == NULL)
        {
            *size = 0;
            return NULL;
        }
        else
        {
            *size = strlen(s);
            return s;
        }
    }
}

int Bootstrap_lua_resources(lua_State *L)
{
#define push(x) lua_pushlstring(L, reinterpret_cast<const char*>(x), sizeof(x))
    push(g_aBootstrapFontDat);
    push(g_aBootstrapFontTab);
    push(g_aBootstrapFontPal);
#undef push
    return 3;
}

int Bootstrap_lua_error_report(lua_State *L)
{
    int iLine = -g_iBootstrapCodeLineNumStart;
    if(lua_load(L, read_bootstrap_line, &iLine, "@bootstrap.cpp") == 0)
    {
        Bootstrap_lua_resources(L);
        lua_pushvalue(L, 1);
        lua_call(L, 4, 0);
        return 0;
    }
    else
        return lua_error(L);
}